﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Reticulum
{
    public partial class FlieSelect : Form
    {
        public FlieSelect()
        {
            InitializeComponent();
        }

        private void FlieSelect_Load(object sender, EventArgs e)
        {
            
            string sql = "select * from FlieInfo";

            DataSet ds = DBHelps.Adapter(sql);

            dataGridView1.AutoGenerateColumns = false;

            dataGridView1.DataSource = ds.Tables[0];

            string sql1 = "select UserName from Users";

            DataSet dst = DBHelps.Adapter(sql1);

            dataGridView2.AutoGenerateColumns = false;

            dataGridView2.DataSource = dst.Tables[0];
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
            

        }

        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //1
            string sql = string.Format("select f.FlieName,f.FlieLength,f.FlieGetTime,f.FlieSuffix,f.original_File_name from FlieInfo f,Users u" +
                 " where f.UserID = u.UserID and UserName = '{0}'", dataGridView2.CurrentCell.Value.ToString());

            DataSet ds = DBHelps.Adapter(sql);

            dataGridView1.AutoGenerateColumns = false;

            dataGridView1.DataSource = ds.Tables[0];
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FlieSelect_Load(sender, e);//刷新

        }

        private void toolStripButton1_Click_1(object sender, EventArgs e)
        {
            string sql = string.Format("select f.FlieName,f.FlieLength,f.FlieGetTime,f.FlieSuffix,f.original_File_name from FlieInfo f,Users u  where f.UserID = u.UserID and UserName = '{0}'", dataGridView2.CurrentCell.Value.ToString());

            DataSet ds = DBHelps.Adapter(sql);
            //获取输入的关键字
            string FlieName = toolStripTextBox1.Text;
            //创建dataview对象
            DataView dv = ds.Tables[0].DefaultView;
            //模糊查询
            dv.RowFilter = string.Format("FlieName like '%{0}%'", FlieName);
            //设置DataView的数据源
            this.dataGridView1.DataSource = dv;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)//按文件名
        {
            string sql = string.Format("select f.FlieName,f.FlieLength,f.FlieGetTime,f.FlieSuffix,f.original_File_name from FlieInfo f,Users u  where f.UserID = u.UserID");

            DataSet ds = DBHelps.Adapter(sql);
            //获取输入的关键字
            string FlieName = toolStripTextBox1.Text;
            //创建dataview对象
            DataView dv = ds.Tables[0].DefaultView;
            //模糊查询
            dv.RowFilter = string.Format("FlieName like '%{0}%'", FlieName);
            //设置DataView的数据源
            this.dataGridView1.DataSource = dv;
        }
    }
}
